def test(n):
    if n % 7 ==0:
        return False
    
    while n>0:
        if n % 10 ==7:
            return False
        n //= 10
        
    return True

sum = 0

n = int(input())
for i in range(1,n+1):
    if test(i):
        sum += i * i
        
print(sum)